package org.megha.blog.example.part13;

import java.util.HashMap;
import java.util.Map;

public class HashMapExample {

	public static void main(String args[]) {
		// A map stores key/value associations.
		// we put in three numbers and their square roots.
		Map<Integer, Double> squareRoots = new HashMap<Integer, Double>();
		squareRoots.put(2, Math.sqrt(2));
		squareRoots.put(16, Math.sqrt(16));
		squareRoots.put(91, Math.sqrt(91));

		// one can loop over all keys in a map
		for (Integer key : squareRoots.keySet()) {
			Double value = squareRoots.get(key);
			System.out.println("sqrt(" + key + ") = " + value);
		}

		// or loop over all key-value entries in a map
		for (Map.Entry<Integer, Double> entry : squareRoots.entrySet()) {
			System.out.println("sqrt(" + entry.getKey() + ") = " + entry.getValue());
		}

		System.out.println("Map is Empty: " + squareRoots.isEmpty());
		System.out.println("Map contains number 91: " + squareRoots.containsKey(91));

		System.out.println("deleting all entries from the map");
		squareRoots.clear();

		System.out.println("Map is Empty: " + squareRoots.isEmpty());
		System.out.println("Map contains number 91: " + squareRoots.containsKey(91));
	}
}
